//
//  WDJLunPanEditTableCell.m

#import "WDJLunPanEditTableCell.h"

static NSString * LunPanEditTableCellId = @"LunPanEditTableCellId";
@interface WDJLunPanEditTableCell()<UITextFieldDelegate>
@property (nonatomic,strong) UILabel *lunPanEditLab;
@property (nonatomic,strong) UITextField *lunPanEditField;
@end
@implementation WDJLunPanEditTableCell
+ (instancetype)lunPanEditTableCell:(UITableView *)tableView{
    WDJLunPanEditTableCell * lunPanEditTableCell = [tableView dequeueReusableCellWithIdentifier:LunPanEditTableCellId];
    if (!lunPanEditTableCell) {
        lunPanEditTableCell = [[WDJLunPanEditTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:LunPanEditTableCellId];
    }
    lunPanEditTableCell.backgroundColor = [UIColor clearColor];
    lunPanEditTableCell.selectionStyle = UITableViewCellSelectionStyleNone;
    lunPanEditTableCell.accessoryType = UITableViewCellAccessoryNone;
    return lunPanEditTableCell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self wdjCreatView];
    }
    return self;
}
- (void)wdjCreatView{
    UIView * lunPanEditBgView = [[UIView alloc] init];
    lunPanEditBgView.backgroundColor = [WDjWholeData wholeColorHexString:@"#FFFFFF" withAlph:0.1];
    lunPanEditBgView.layer.cornerRadius = [WDjWholeData wholeScreewRatio:10];
    lunPanEditBgView.clipsToBounds = YES;
    [self.contentView addSubview:lunPanEditBgView];
    [lunPanEditBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([WDjWholeData wholeScreewRatio:30]));
        make.right.equalTo(@(-[WDjWholeData wholeScreewRatio:30]));
        make.height.equalTo(@([WDjWholeData wholeScreewRatio:100]));
        make.top.equalTo(@([WDjWholeData wholeScreewRatio:0]));
    }];
    UIButton * lunPanEditHeadBtn = [[UIButton alloc] init];
    [lunPanEditHeadBtn setBackgroundImage:[WDjWholeData wholeImageNamed:@"wdj_LunPanDelect"] forState:UIControlStateNormal];
    [lunPanEditHeadBtn addTarget:self action:@selector(lunPanEdit) forControlEvents:UIControlEventTouchUpInside];
    [lunPanEditBgView addSubview:lunPanEditHeadBtn];
    [lunPanEditHeadBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([WDjWholeData wholeScreewRatio:24]));
        make.centerY.equalTo(lunPanEditBgView);
        make.height.equalTo(@([WDjWholeData wholeScreewRatio:42]));
        make.width.equalTo(@([WDjWholeData wholeScreewRatio:42]));
    }];
    self.lunPanEditLab = [[UILabel alloc] init];
    self.lunPanEditLab.textColor = [WDjWholeData wholeColorHexString:@"#FFFFFF"];
    self.lunPanEditLab.font = [UIFont systemFontOfSize:[WDjWholeData wholeScreewRatio:30] weight:UIFontWeightRegular];
    [lunPanEditBgView addSubview:self.lunPanEditLab];
    [self.lunPanEditLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lunPanEditHeadBtn.mas_right).offset([WDjWholeData wholeScreewRatio:19]);
        make.centerY.equalTo(lunPanEditHeadBtn);
        make.height.equalTo(@([WDjWholeData wholeScreewRatio:42]));
    }];
    self.lunPanEditField = [[UITextField alloc] init];
    self.lunPanEditField.placeholder = @"请输入选项名称";
    NSDictionary *attributeDic = @{NSForegroundColorAttributeName:[WDjWholeData wholeColorHexString:@"#9FA4B8"]};
    NSAttributedString *attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入选项名称" attributes:attributeDic];
    self.lunPanEditField.attributedPlaceholder = attributedPlaceholder;
    self.lunPanEditField.textColor = [WDjWholeData wholeColorHexString:@"#FFFFFF"];
    self.lunPanEditField.font = [UIFont systemFontOfSize:[WDjWholeData wholeScreewRatio:30] weight:UIFontWeightRegular];
    self.lunPanEditField.delegate = self;
    self.lunPanEditField.hidden = true;
    [lunPanEditBgView addSubview:self.lunPanEditField];
    [self.lunPanEditField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lunPanEditHeadBtn.mas_right).offset([WDjWholeData wholeScreewRatio:19]);
        make.top.equalTo(@([WDjWholeData wholeScreewRatio:0]));
        make.bottom.equalTo(@([WDjWholeData wholeScreewRatio:0]));
        make.right.equalTo(@([WDjWholeData wholeScreewRatio:0]));
    }];
}
-(void)setLunPanEditName:(NSString *)lunPanEditName{
    _lunPanEditName = lunPanEditName;
    if(_lunPanEditName.length > 0){
        self.lunPanEditLab.hidden = false;
        self.lunPanEditField.hidden = true;
        self.lunPanEditLab.text = _lunPanEditName;
    }else{
        self.lunPanEditLab.hidden = true;
        self.lunPanEditField.hidden = false;
        self.lunPanEditField.text = _lunPanEditName;
    }
}
- (void)lunPanEdit{
    if (self.LunPanDelectBlock) {
        self.LunPanDelectBlock();
    }
}
#pragma mark -- UITextFieldDelegate
- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (self.LunPanEditBlock) {
        self.LunPanEditBlock(self.lunPanEditField.text);
    }
}
@end
